package com.shaoyu.tools.event.config;

import com.shaoyu.tools.event.EnableEventBus;
import com.shaoyu.tools.event.core.AsyncFilterEventBus;
import com.shaoyu.tools.event.core.FilterEventBus;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

/**
 * @author shaoyu
 * @date 2022/11/21 17:56
 */
public class EventBusImportSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(EnableEventBus.class.getName());
        boolean async = (boolean)annotationAttributes.get("async");
        return async? new String[]{
                AsyncFilterEventBus.class.getName()
        } : new String[]{
                FilterEventBus.class.getName()
        };
    }
}
